<?php
//error_reporting(E_ALL);

define('DIR_ROOT', substr(dirname(__FILE__), 0, -5).'/');
define('TPL_ROOT', DIR_ROOT.'view/');
define('IS_SEA', defined('SAE_ACCESSKEY') ? true : false);
require_once(DIR_ROOT . '/core/config.inc.php');

if(!isset($_SERVER['SCRIPT_URI']))
{
	$_SERVER['SCRIPT_URI'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}

//自动加载类
function __autoload ($class_name) {
	if(!class_exists($class_name, false)) {
		$class_name = strtolower($class_name);

		$offset = strpos($class_name, '_');
		$dirname = substr($class_name , 0, strpos($class_name, '_'));
		$filename = substr($class_name , $offset+1) . '.php';

		include DIR_ROOT . 'core/' . $dirname . '/' . $filename;
	}
}

//mb_internal_encoding('utf-8');

//SEA在线调试
DEBUG && IS_SEA && sae_set_display_errors(true);


/**
 * 取得微博操作类
 * @staticvar string $object
 * @return cls_weibo
 */
function weibo_obj()
{
	static $object = null;

	if($object === null)
	{
		$class = IS_SEA ? 'cls_weibosae' : 'cls_weibo';
		$object = new $class(WB_AKEY);
	}

	return $object;
}

/**
 * 取得存储操作对象
 * @return cls_storage
 */
function storage_obj()
{
	static $object = null;
	if($object === null)
	{
		$class = IS_SEA ? 'SaeStorage' : 'cls_storage';
		$object = new $class();
	}

	return $object;
}

/**
 * 加载微博类(Oauth)
 */
function load_weiboauth()
{
	if(!IS_SEA)
	{
		include_once( DIR_ROOT . 'core/cls/weibooauth.php' );
	}
	else
	{
		include_once( 'saet.ex.class.php' );
	}
	
}